package com.zzyl.nursing.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageInfo;
import com.zzyl.serve.domain.NursingProject;
import com.zzyl.serve.mapper.NursingProjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.zzyl.nursing.service.IMemberNursingProjectService;

import static com.zzyl.common.utils.PageUtils.startPage;

/**
 * 护理项目Service业务层处理
 *
 * @author laoYe
 * @date 2025-10-27
 */
@Service
@Slf4j
public class MemberNursingProjectServiceImpl extends ServiceImpl<NursingProjectMapper, NursingProject> implements IMemberNursingProjectService {
    @Autowired
    private NursingProjectMapper nursingProjectMapper;

    /**
     * 查询护理项目
     *
     * @param id 护理项目主键
     * @return 护理项目
     */
    @Override
    public NursingProject selectNursingProjectById(Long id) {
        return getById(id);
    }

    /**
     * 查询护理项目列表
     *
     * @param nursingProject 护理项目
     * @return 护理项目
     */
    @Override
    public Map<String, Object> selectNursingProjectList(NursingProject nursingProject) {
        log.info("查询护理项目列表{}", nursingProject);

        // 执行分页查询
        startPage();  // 确保这里调用了分页
        List<NursingProject> list = nursingProjectMapper.selectNursingProjectList(nursingProject);

        // 获取分页信息
        PageInfo<NursingProject> pageInfo = new PageInfo<>(list);

        // 构建符合前端要求的格式
        Map<String, Object> result = new HashMap<>();
        result.put("total", pageInfo.getTotal());
        result.put("rows", list);
        result.put("code", 200);
        result.put("msg", "查询成功");

        log.info("查询护理项目列表返回值{}", result);
        return result;
    }

}
